//
//  ViewController.m
//  InteractiveNotification
//
//  Created by GuochengLiu on 2017/1/16.
//  Copyright © 2017年 sumavision. All rights reserved.
//

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#import "ViewController.h"
#import "Counter.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self _updateLabel];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateLabel) name:@"CounterDidChange" object:nil];

}

- (void)_updateLabel
{
    self.countLabel.text = [NSString stringWithFormat:@"%li", (long)[Counter currentValue]];
    
    NSLog(@"!!!!!!!!!! countLable Updated: %@", self.countLabel.text);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (IBAction)onHitScheduleButton:(UIButton *)sender {
    [self _setupLocationNotification];
}

- (void)_setupLocationNotification
{
    UILocalNotification *localNoti = [[UILocalNotification alloc] init];
    localNoti.alertBody =  @"Hey! Update your counter";
    localNoti.soundName = UILocalNotificationDefaultSoundName;
    localNoti.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
    localNoti.category = @"COUNT_CATEGORY";
    
    [[UIApplication sharedApplication] scheduleLocalNotification:localNoti];
}

#pragma GCC diagnostic pop

@end
